﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Yunzuan.Foundation.Web;

namespace Yunzuan.Foundation.Web.Pages
{
    public class BasePage : System.Web.UI.Page
    {
        #region 基础Session信息

        #region Const

        private static readonly string SESSION_NAME_USER_ID = "UserID";
        private static readonly string SESSION_NAME_USER_NAME = "UserName";
        private static readonly string SESSION_NAME_REAL_NAME = "RealName";

        #endregion

        #region UserID

        private int? _userID;
        public int UserID
        {
            get
            {
                if (!_userID.HasValue)
                {
                    _userID = SessionManager.GetSession<int>(SESSION_NAME_USER_ID);
                }
                return _userID.Value;
            }
            set
            {
                _userID = value;
                SessionManager.SetSession(SESSION_NAME_USER_ID, value);
            }
        } 

        #endregion

        #region UserName

        private string _userName;
        public string UserName
        {
            get
            {
                if (string.IsNullOrEmpty(_userName))
                {
                    _userName = SessionManager.GetSession(SESSION_NAME_USER_NAME);
                }
                return _userName;
            }
            set
            {
                _userName = value;
                SessionManager.SetSession(SESSION_NAME_USER_NAME, value);
            }
        }

        #endregion

        #region RealName

        private string _realName;
        public string RealName
        {
            get
            {
                if (string.IsNullOrEmpty(_realName))
                {
                    _realName = SessionManager.GetSession(SESSION_NAME_REAL_NAME);
                }
                return _realName;
            }
            set
            {
                _realName = value;
                SessionManager.SetSession(SESSION_NAME_REAL_NAME, value);
            }
        }

        #endregion

        #endregion

        public bool IsLogin()
        {
            return this.UserID > 0;
        }

        /// <summary>
        /// 获取多语言资源内容
        /// </summary>
        /// <param name="resourceId"></param>
        /// <returns></returns>
        public string GetResource(string resourceId)
        {
            //TODO: 取资源内容
            return this.ResourceFile + "\\" + this.Language + "\\" + resourceId;
        }

        /// <summary>
        /// 资源文件
        /// </summary>
        protected virtual string ResourceFile
        {
            get
            {
                return string.Empty;
            }
        }
        /// <summary>
        /// 资源文件
        /// </summary>
        protected virtual string Language
        {
            get
            {
                return "cn";
            }
        }
    }
}
